package com.ktgj.flight.controller;

import java.util.Collections;
import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ktgj.flight.domain.FlightOrderInfoTicketNo;
import com.ktgj.flight.domain.vo.JourneyFlightOrderInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.flight.domain.FlightOrderInfoTickets;
import com.ktgj.flight.service.IFlightOrderInfoTicketsService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 机票预订_机票订单机票明细Controller
 * 
 * @author ruoyi
 * @date 2021-10-26
 */
@ControllerAdvice
@RestController
@RequestMapping("/infotickets")
public class FlightOrderInfoTicketsController extends BaseController
{
    @Autowired
    private IFlightOrderInfoTicketsService flightOrderInfoTicketsService;

    /**
     * 查询机票预订_机票订单机票明细列表
     */
    @PreAuthorize(hasPermi = "flight:tickets:list")
    @GetMapping("/list")
    public TableDataInfo list(FlightOrderInfoTickets flightOrderInfoTickets)
    {
        startPage();
        List<FlightOrderInfoTickets> list = flightOrderInfoTicketsService.selectFlightOrderInfoTicketsList(flightOrderInfoTickets);
        return getDataTable(list);
    }

    /**
     * 查询机票预订_机票订单机票明细列表
     * @param flightOrderInfoTickets
     * @return
     */
    @PostMapping("/orderInfoTicketsList")
    public List<FlightOrderInfoTickets> orderInfoTicketsList(@RequestBody FlightOrderInfoTickets flightOrderInfoTickets) {
        List<FlightOrderInfoTickets> list = flightOrderInfoTicketsService.selectFlightOrderInfoTicketsList(flightOrderInfoTickets);
        return list;
    }

    /**
     * 导出机票预订_机票订单机票明细列表
     */
    @PreAuthorize(hasPermi = "flight:tickets:export")
    @Log(title = "机票预订_机票订单机票明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FlightOrderInfoTickets flightOrderInfoTickets) throws IOException
    {
        List<FlightOrderInfoTickets> list = flightOrderInfoTicketsService.selectFlightOrderInfoTicketsList(flightOrderInfoTickets);
        ExcelUtil<FlightOrderInfoTickets> util = new ExcelUtil<FlightOrderInfoTickets>(FlightOrderInfoTickets.class);
        util.exportExcel(response, list, "机票预订_机票订单机票明细数据");
    }

    /**
     * 获取机票预订_机票订单机票明细详细信息
     */
    @PreAuthorize(hasPermi = "flight:tickets:query")
    @GetMapping(value = "/{orderInfoTicketsId}")
    public AjaxResult getInfo(@PathVariable("orderInfoTicketsId") Long orderInfoTicketsId)
    {
        return AjaxResult.success(flightOrderInfoTicketsService.selectFlightOrderInfoTicketsById(orderInfoTicketsId));
    }

    /**
     * 新增机票预订_机票订单机票明细
     */
    @PreAuthorize(hasPermi = "flight:tickets:add")
    @Log(title = "机票预订_机票订单机票明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FlightOrderInfoTickets flightOrderInfoTickets)
    {
        return toAjax(flightOrderInfoTicketsService.insertFlightOrderInfoTickets(flightOrderInfoTickets));
    }

    /**
     * 修改机票预订_机票订单机票明细
     */
    @PreAuthorize(hasPermi = "flight:tickets:edit")
    @Log(title = "机票预订_机票订单机票明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FlightOrderInfoTickets flightOrderInfoTickets)
    {
        return toAjax(flightOrderInfoTicketsService.updateFlightOrderInfoTickets(flightOrderInfoTickets));
    }

    /**
     * 修改票号
     * @param ticketNo
     * @return
     */
    @PostMapping("/updateTicketNo")
    public AjaxResult updateTicketNo(@RequestBody FlightOrderInfoTicketNo ticketNo) {
        return toAjax(flightOrderInfoTicketsService.updateFlightOrderInfoTicketsByTicketNo(ticketNo));
    }

    /**
     * 删除机票预订_机票订单机票明细
     */
    @PreAuthorize(hasPermi = "flight:tickets:remove")
    @Log(title = "机票预订_机票订单机票明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderInfoTicketsIds}")
    public AjaxResult remove(@PathVariable Long[] orderInfoTicketsIds)
    {
        return toAjax(flightOrderInfoTicketsService.deleteFlightOrderInfoTicketsByIds(orderInfoTicketsIds));
    }

    /**
     * 查看行程用
     * @param orderID
     * @return
     */
    @PostMapping("/queryFlightOrderTrip")
    public Map<String, Object> queryFlightOrderTrip(@RequestParam("orderId") Long orderID) {
        Map<String, Object> flightOrderTrip = flightOrderInfoTicketsService.queryFlightOrderTrip(orderID);
        return flightOrderTrip;
    }

    /**
     * 定制行程-单程
     * @param customerId
     * @return
     */
    @PostMapping("/queryInfoTickets")
    public Map<String, Object> queryInfoTickets(@RequestParam("customerId") Long customerId) {
        Map<String, Object> infoTickets = flightOrderInfoTicketsService.queryInfoTickets(customerId);
        return infoTickets;
    }

    /**
     * 回填票号
     * */
    @PostMapping("/backfillTicketNumber")
    public int backfillTicketNumber(@RequestBody Map<String, Object> map){
        String ticketNumber = map.get("ticketNumber").toString();
        Long id = Long.valueOf(map.get("id").toString());
        int i = flightOrderInfoTicketsService.backfillTicketNumber(id, ticketNumber);
        return i;
    }

    /**
     * 订单号获取乘客id列表
     * */
    @PostMapping("/flightOrderIdList")
    public AjaxResult flightOrderIdList(@RequestBody Map<String, Object> map){
        Long orderId = Long.valueOf(map.get("orderId").toString());
        List<Long> idList = flightOrderInfoTicketsService.flightOrderIdList(orderId);
        return AjaxResult.success(idList);
    }

    /**
     * 机票订单详细（远程）
     * */
    @PostMapping("/order")
    public boolean orderDetails(@RequestBody Map<String, Object> map){
        String ticketNum = map.get("ticketNum").toString();
        boolean flag = flightOrderInfoTicketsService.order(ticketNum);
        return flag;
    }
}
